import { useI18n } from 'vue-i18n'
import {computed} from "vue";

const useLocale = () => {
    const i18n = useI18n()
    const locale = computed(() => {
        return i18n.locale.value
    })
    const changeLocale = (value: string) => {
        if (i18n.locale.value === value) return
        i18n.locale.value = value
        localStorage.setItem('base-vue-locale', value)
    }
    const getLocaleParams = (): string => {
        return i18n.locale.value === 'zh' ? 'en' : 'zh'
    }
    return { locale, changeLocale, getLocaleParams }
}

export default useLocale